package com.gsn.chooseGame;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.mercurry.MercuryClient;
import com.gsn.engine.utility.UtilityGettor;
import com.gsn.name.StatePortal;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;

public class GalleryGame extends Group implements ClickListener {
	GsnImageButton pokerButton;
	GsnImageButton talaButton;
	GsnImageButton tienlenButton;
	GsnImageButton caroButton;
	public int numGame = 4;
	public ChooseGameLayer parent;

	public GalleryGame(float width, ChooseGameLayer parent) {
		float pad;
		this.parent = parent;
		PortalTexture portalTexture = PortalTexture.inst();

		caroButton = new GsnImageButton(portalTexture.caroButton, portalTexture.caroButtonPress);
		portalTexture.scaleActor(caroButton);
		addActor(caroButton);
		caroButton.setClickListener(this);
		pad = (width - caroButton.getRealWidth() * 3.2f) / 3;
		caroButton.x = pad;

		Image caroComming = new Image(portalTexture.iconComming);
		portalTexture.scaleActor(caroComming);
		addActor(caroComming);
		caroComming.x = caroButton.x + caroButton.getRealWidth() * 0.06f;
		caroComming.y = caroButton.getRealHeight() * 0.05f;

		pokerButton = new GsnImageButton(portalTexture.pokerButton, portalTexture.pokerButtonPress);
		portalTexture.scaleActor(pokerButton);
		addActor(pokerButton);
		pokerButton.setClickListener(this);
		pokerButton.x = pad + caroButton.x + caroButton.getRealWidth();

		tienlenButton = new GsnImageButton(portalTexture.tienlenButton, portalTexture.tienlenButtonPress);
		portalTexture.scaleActor(tienlenButton);
		addActor(tienlenButton);
		tienlenButton.setClickListener(this);
		tienlenButton.x = pad + pokerButton.x + pokerButton.getRealWidth();

		Image tienLenComming = new Image(portalTexture.iconComming);
		portalTexture.scaleActor(tienLenComming);
		addActor(tienLenComming);
		tienLenComming.x = tienlenButton.x + tienlenButton.getRealWidth() * 0.06f;
		tienLenComming.y = tienlenButton.getRealHeight() * 0.05f;

		talaButton = new GsnImageButton(portalTexture.talaButton, portalTexture.talaButtonPress);
		portalTexture.scaleActor(talaButton);
		talaButton.setClickListener(this);
		addActor(talaButton);
		talaButton.x = pad + tienlenButton.x + tienlenButton.getRealWidth();

		Image talaComming = new Image(portalTexture.iconComming);
		portalTexture.scaleActor(talaComming);
		addActor(talaComming);
		talaComming.x = talaButton.x + talaButton.getRealWidth() * 0.06f;
		talaComming.y = talaButton.getRealHeight() * 0.05f;

		this.width = caroButton.getRealWidth() * numGame + numGame * pad;
		this.height = caroButton.getRealHeight();

	}

	@Override
	public void click(Actor actor, float x, float y) {
		// TODO Auto-generated method stub

		if (MyPoker.game.statePortal != StatePortal.CHOOSE_GAME)
			return;

		System.out.println(" chay qua duoc day  **************   ");
		GsnParticleActor par = new GsnParticleActor(PortalTexture.inst().clickEff);
		Vector2 v = ActorUtility.getCoordinate(actor, x, y, this);

		par.setPostition(v.x, v.y);

		par.act(100000);
		parent.showParticle(this, v.x, v.y);
		// addActor(par);
		// par.start();
		PokerSound.playClick();

		if (actor == caroButton) {
			System.out.println("caro");
		} else if (actor == pokerButton) {
			System.out.println("xi to");
			UtilityGettor.inst().showProgressDialog("Tải game", "Đang tải game..");
			MyPoker.client = new MercuryClient(MyPoker.server, 443, MyPoker.game);
			MyPoker.client.connect();
			MyPoker.game.statePortal = StatePortal.CHOOSING_GAME;

		}
	}
}
